<template>
  <div id="selectionlist">
    <el-breadcrumb separator=">">
      <el-breadcrumb-item :to="{ path: '/' }">系统首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/selection' }">干部选任</el-breadcrumb-item>
      <el-breadcrumb-item>已办理事项</el-breadcrumb-item>
    </el-breadcrumb>
    <section class="wboxs">
    <!--工具条-->
      <el-form :inline="true" :model="filters">
          <el-form-item>
            <el-radio-group v-model="taskflag" @change="radioChange">
              <el-radio-button label="待办理事项列表">
              </el-radio-button>
              <el-radio-button label="已办理事项列表">
              </el-radio-button>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="人选姓名">
            <el-input v-model="filters.realName" placeholder="姓名" @change="getList" style="width:90px;"></el-input>
          </el-form-item>
          <el-form-item label="接收用户">
            <el-input v-model="filters.receiveUserName" placeholder="姓名" @change="getList" style="width:90px;"></el-input>
          </el-form-item>
          <el-form-item label="环节">
            <el-select v-model="filters.step" placeholder="请选择" @change="getList" style="width:170px;">
              <el-option label="全部" value=""></el-option>
              <el-option v-for="(item, index) in steplist" :key="index" :label="item" :value="index+1"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="状态">
            <el-select v-model="filters.state" placeholder="请选择" @change="getList" style="width:100px;">
              <el-option label="全部" value=""></el-option>
              <el-option label="已办理" value="1"></el-option>
              <el-option label="未办理" value="0"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="发送时间">
            <el-date-picker v-model="filters.sendTime" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" @change="getList" style="width:230px;"></el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="getList" icon="el-icon-search">查询</el-button>
          </el-form-item>
      </el-form>
    </section>
    <section class="wboxd" style="margin-top:10px">
      <!--列表-->
      <el-table :data="tasklist" highlight-current-row v-loading="listLoading" style="width: 100%;" :height="tableHeight" border @sort-change='sortChange'>
        <el-table-column label="环节" width="200" sortable="custom" prop="step">
          <template slot-scope="scope">
            {{stepid2name(scope.row.step)}}
          </template>
        </el-table-column>
        <el-table-column label="接收用户" prop="receiveUserName" width="200" sortable="custom">
        </el-table-column>
        <el-table-column label="发送时间" prop="sendTime" width="200" sortable="custom">
        </el-table-column>
        <el-table-column label="人选姓名" prop="realName" width="200" sortable="custom">
        </el-table-column>
        <el-table-column label="状态" width="200" prop="state" sortable="custom">
          <template slot-scope="scope">
            {{stateid2name(scope.row.state)}}
          </template>
        </el-table-column>
        <el-table-column :label="opiniontitle" prop="opinion" align="left">
        </el-table-column>
        <el-table-column label="操作" width="100">
          <template slot-scope="scope">
            <el-button size="small" @click="delundo(scope.row.id)" type="primary" v-if="scope.row.state===0">撤回</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination :total="totalnum" :page-size="pageSize" @current-change="handleCurrentChange" :current-page="pageNum" @size-change="handleSizeChange" :page-sizes="[10, 20, 30, 50]" layout="total, sizes, prev, pager, next, jumper"></el-pagination>
      </div>
    </section>
  </div>
</template>

<script>
export default {
  data () {
    return {
      taskflag: '已办理事项列表',
      unitName: '',
      steplist: ['动议后续环节选择', '凡提四必', '民主推荐', '考察', '讨论决定', '公示', '报中组部备案', '任职发文', '任职谈话', '廉政谈话', '宣布'],
      filters: {
        realName: '',
        receiveUserName: '',
        sendTime: '',
        step: '',
        state: '',
        sortBy: 'id',
        isAsc: true
      },
      opiniontitle: '',
      tasklist: [
      ],
      totalnum: 0,
      pageNum: 1,
      pageSize: 20,
      Sortkey: 'id',
      Isace: false,
      listLoading: false,
      changeSizeFlag: false,
      tableHeight: 100
    }
  },
  methods: {
    radioChange () {
      if (this.taskflag === '待办理事项列表') {
        if (this.inRoles('ROLE_banshirenyuan')) {
          if (this.unitName === '干部监督处') {
            this.$router.push({path: '/selection/taskjdccn'})
          } else {
            this.$router.push({path: '/selection/taskcn'})
          }
        } else if (this.inRoles('ROLE_sizhang') || this.inRoles('ROLE_fusizhang')) {
          this.$router.push({path: '/selection/taskleader'})
        } else if (this.inRoles('ROLE_chuzhang')) {
          if (this.unitName === '干部监督处') {
            this.$router.push({path: '/selection/taskjdc'})
          } else {
            this.$router.push({path: '/selection/task'})
          }
        }
      }
    },
    stepid2name (id) {
      switch (id) {
        case 1:
          return '动议后续环节选择'
        case 2:
          return '凡提四必'
        case 3:
          return '民主推荐'
        case 4:
          return '考察'
        case 5:
          return '讨论决定'
        case 6:
          return '公示'
        case 7:
          return '报中组部备案'
        case 8:
          return '任职发文'
        case 9:
          return '任职谈话'
        case 10:
          return '廉政谈话'
        case 11:
          return '宣布'
        case 12:
          return '事前报告'
        case 13:
          return '征求协管方意见'
        case 21:
          return '凡提四必-查核干部档案'
        case 22:
          return '凡提四必-查核有关事项'
        case 23:
          return '凡提四必-征求纪检监察部门意见'
        case 24:
          return '凡提四必-线索举报调查'
      }
    },
    stateid2name (id) {
      switch (id) {
        case 1:
          return '已办理'
        case 0:
          return '未办理'
      }
    },
    handleSizeChange (val) {
      this.changeSizeFlag = true
      this.pageNum = 1
      this.pageSize = val
      this.getList()
    },
    handleCurrentChange (val) {
      if (this.changeSizeFlag === false) {
        this.pageNum = val
        this.getList()
      }
    },
    getList () {
      let para = {
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        realName: this.filters.realName,
        receiveUserName: this.filters.receiveUserName,
        step: this.filters.step,
        state: this.filters.state,
        sortBy: this.Sortkey,
        isAsc: this.Isace
      }
      if (this.filters.sendTime) {
        para = {
          pageNum: this.pageNum,
          pageSize: this.pageSize,
          realName: this.filters.realName,
          receiveUserName: this.filters.receiveUserName,
          step: this.filters.step,
          state: this.filters.state,
          sendTimeStart: new Date(this.filters.sendTime[0] + ' 00:00:00'),
          sendTimeEnd: new Date(this.filters.sendTime[1] + ' 23:59:59'),
          sortBy: this.Sortkey,
          isAsc: this.Isace
        }
      }
      this.listLoading = true
      this.$http
        .post(this.$http.defaults.selectionAPI + `api/selection/approve/getUserSendedApproveList`, para)
        .then(response => {
          if (response.data.success) {
            this.listLoading = false
            this.tasklist = response.data.result.records
            this.totalnum = response.data.result.total
            this.changeSizeFlag = false
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
    },
    // 排序
    sortChange: function (column, prop, order) {
      this.Sortkey = column.prop
      if (column.order === 'ascending') {
        this.Isace = true
      } else {
        this.Isace = false
      }
      this.getList()
    },
    delundo (id) {
      this.$http
        .get(this.$http.defaults.selectionAPI + `api/selection/approve/updateUndoApprove?id=` + id)
        .then(response => {
          if (response.data.success) {
            this.$message({
              message: '操作成功',
              type: 'success'
            })
            this.getList()
          } else {
            this.$message({
              message: '操作失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          this.$message({
            message: '操作失败:' + error,
            type: 'error'
          })
        })
    },
    inRoles (str) {
      console.log(str)
      let arr = JSON.parse(localStorage.getItem('Roles'))
      // arr = 'aaabbROLE_admin'
      if (arr.indexOf(str) === -1) {
        return false
      } else {
        return true
      }
    },
    tableresize (obj) {
      var clientHeight = 0
      if (document.body.clientHeight && document.documentElement.clientHeight) {
        clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      } else {
        clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight
      }
      obj.$nextTick(function () {
        obj.tableHeight = clientHeight - 263
      })
    }
  },
  mounted () {
    this.unitName = localStorage.getItem('unitName')
    if (this.inRoles('ROLE_sizhang') || this.inRoles('ROLE_fusizhang')) {
      this.opiniontitle = '批示意见'
    } else {
      this.opiniontitle = '办理提示'
    }
    this.getList()
    this.tableresize(this)
    let _this = this
    window.onresize = function windowResize () {
      // 通过捕获系统的onresize事件触发我们需要执行的事件
      _this.tableresize(_this)
    }
  }
}
</script>
<style>
  .wboxd .el-table th{
    font-weight: normal;
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
    text-align: center;
    border-right: #95B8E7 solid 1px;
    border-bottom: #95B8E7 solid 1px;
    min-height: 30px;
    line-height:30px;
  }
  .wboxd .el-table td, .el-table th{
    padding:0;
    font-size:var(--size14) !important;
    line-height: 20px;
    font-family: '宋体';
    text-align:center
  }
  .tableth{
    background-image: linear-gradient(to bottom , #f8f8f8, #efefef);
    height:33px;
  }
  #selectionlist .wboxs{
    height:45px;
    padding-top:10px;
  }
  #selectionlist .el-table__row{
    height: 50px;
  }
  #selectionlist #legent{
    float:right;
    margin-right: 20px;
  }
  #selectionlist #legent div{
    float:left;
    line-height: 42px;
    font-size:var(--size14);
  }
  #selectionlist #legent i{
    width: 30px;
    height: 30px;
    background-position: center center;
    background-repeat: no-repeat;
    float: left;
    display: block;
    margin:5px 5px 0 10px;
  }
  #selectionlist .cell i{
    background-position: center center;
    background-repeat: no-repeat;
    float: center;
    display: block;
    cursor: pointer;
    margin:0 auto;
  }
  .wboxd .el-table__row .is-left .cell{
    text-align: left !important;
  }
</style>
<style scoped>
  h1{
    font-size:var(--size16) !important;
    font-weight: bolder;
    height: 30px;
    border-bottom: 1px solid #95B8E7;
    font-family: '宋体';
    line-height: 30px;
    color: #000;
    padding-left:10px;
    background-image: linear-gradient(to bottom , #EEF4FF, #E0ECFF);
    margin:0;
  }
  .el-pagination{
    float: left;
    padding:7px 10px;
  }
  .wboxs{
    padding:5px 15px;
    width: calc(100% - 30px);
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
  }
  .wboxd{
    padding:0;
    width: calc(100% - 0px);
    background: #fff;
    border: 1px solid #95B8E7;
    margin:0 10px;
    overflow: hidden;
  }
</style>
